package com.csun.cmny.provider.pojo;

import com.csun.cmny.provider.validator.RoleValid;
import org.hibernate.validator.constraints.NotEmpty;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

public class Role implements Serializable {
	@NotNull(message = "{id.empty}", groups = {RoleValid.class})
    private Integer roleid;	//角色id

	@NotEmpty(message = "{Role.name.notnull}", groups = {RoleValid.class})
	@Size(min = 1, max = 32, message = "{Role.name.length}", groups = {RoleValid.class})
    private String rolename;//角色名称

    private String rolecode;//角色code

    @NotEmpty(message = "{Role.description.notnull}", groups = {RoleValid.class})
	@Size(min = 1, max = 64, message = "{Role.description.length}", groups = {RoleValid.class})
    private String roledesc;//角色描述

    private Integer homeid;	//机构id

    private Integer isedit;	//是否可以编辑
    
    @Range(min=1, max=2147483647, message="{Role.add.range.error}", groups = {RoleValid.class})
    private Integer defaultrole;//新建角色时默认角色id

    private Integer valid;	//是否有效

    private Date createtime;//创建时间

    private Date modifytime;//修改时间

    private Long modifier;	//修改者id
    
    private List<Permission> permList;//权限集合
    
    private List<User>	userList;//用户集合

    private static final long serialVersionUID = 1L;

    public Integer getRoleid() {
        return roleid;
    }

    public void setRoleid(Integer roleid) {
        this.roleid = roleid;
    }

    public String getRolename() {
        return rolename;
    }

    public void setRolename(String rolename) {
        this.rolename = rolename;
    }

    public String getRolecode() {
        return rolecode;
    }

    public void setRolecode(String rolecode) {
        this.rolecode = rolecode;
    }

    public String getRoledesc() {
        return roledesc;
    }

    public void setRoledesc(String roledesc) {
        this.roledesc = roledesc;
    }

    public Integer getHomeid() {
        return homeid;
    }

    public void setHomeid(Integer homeid) {
        this.homeid = homeid;
    }

    public Integer getIsedit() {
        return isedit;
    }

    public void setIsedit(Integer isedit) {
        this.isedit = isedit;
    }

    public Integer getDefaultrole() {
        return defaultrole;
    }

    public void setDefaultrole(Integer defaultrole) {
        this.defaultrole = defaultrole;
    }

    public Integer getValid() {
        return valid;
    }

    public void setValid(Integer valid) {
        this.valid = valid;
    }

    public Date getCreatetime() {
        return createtime;
    }

    public void setCreatetime(Date createtime) {
        this.createtime = createtime;
    }

    public Date getModifytime() {
        return modifytime;
    }

    public void setModifytime(Date modifytime) {
        this.modifytime = modifytime;
    }

    public Long getModifier() {
        return modifier;
    }

    public void setModifier(Long modifier) {
        this.modifier = modifier;
    }

    public List<Permission> getPermList() {
		return permList;
	}

	public void setPermList(List<Permission> permList) {
		this.permList = permList;
	}

	public List<User> getUserList() {
		return userList;
	}

	public void setUserList(List<User> userList) {
		this.userList = userList;
	}

	@Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        Role other = (Role) that;
        return (this.getRoleid() == null ? other.getRoleid() == null : this.getRoleid().equals(other.getRoleid()))
            && (this.getRolename() == null ? other.getRolename() == null : this.getRolename().equals(other.getRolename()))
            && (this.getRolecode() == null ? other.getRolecode() == null : this.getRolecode().equals(other.getRolecode()))
            && (this.getRoledesc() == null ? other.getRoledesc() == null : this.getRoledesc().equals(other.getRoledesc()))
            && (this.getHomeid() == null ? other.getHomeid() == null : this.getHomeid().equals(other.getHomeid()))
            && (this.getIsedit() == null ? other.getIsedit() == null : this.getIsedit().equals(other.getIsedit()))
            && (this.getDefaultrole() == null ? other.getDefaultrole() == null : this.getDefaultrole().equals(other.getDefaultrole()))
            && (this.getValid() == null ? other.getValid() == null : this.getValid().equals(other.getValid()))
            && (this.getCreatetime() == null ? other.getCreatetime() == null : this.getCreatetime().equals(other.getCreatetime()))
            && (this.getModifytime() == null ? other.getModifytime() == null : this.getModifytime().equals(other.getModifytime()))
            && (this.getModifier() == null ? other.getModifier() == null : this.getModifier().equals(other.getModifier()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getRoleid() == null) ? 0 : getRoleid().hashCode());
        result = prime * result + ((getRolename() == null) ? 0 : getRolename().hashCode());
        result = prime * result + ((getRolecode() == null) ? 0 : getRolecode().hashCode());
        result = prime * result + ((getRoledesc() == null) ? 0 : getRoledesc().hashCode());
        result = prime * result + ((getHomeid() == null) ? 0 : getHomeid().hashCode());
        result = prime * result + ((getIsedit() == null) ? 0 : getIsedit().hashCode());
        result = prime * result + ((getDefaultrole() == null) ? 0 : getDefaultrole().hashCode());
        result = prime * result + ((getValid() == null) ? 0 : getValid().hashCode());
        result = prime * result + ((getCreatetime() == null) ? 0 : getCreatetime().hashCode());
        result = prime * result + ((getModifytime() == null) ? 0 : getModifytime().hashCode());
        result = prime * result + ((getModifier() == null) ? 0 : getModifier().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", roleid=").append(roleid);
        sb.append(", rolename=").append(rolename);
        sb.append(", rolecode=").append(rolecode);
        sb.append(", roledesc=").append(roledesc);
        sb.append(", homeid=").append(homeid);
        sb.append(", isedit=").append(isedit);
        sb.append(", defaultrole=").append(defaultrole);
        sb.append(", valid=").append(valid);
        sb.append(", createtime=").append(createtime);
        sb.append(", modifytime=").append(modifytime);
        sb.append(", modifier=").append(modifier);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}